#------------------------------------------------------------------------------
# osxSwUpdate.pl
#   Plugin for MacRipper
#   Get OS last software update times
#
# Change history
#   20120605 [fpi] * released
#
# References
#
# copyright 2012 Francesco Picasso <francesco.picasso@gmail.com>
#------------------------------------------------------------------------------

package osxSwUpdate;
use strict;

#------------------------------------------------------------------------------

my %config = (
    version         => 20120605,
    hasDescr        => 1,
    hasRefs         => 0,
	applyto			=> 'osx',
	srctype			=> "plist",
   	srcfile		    => "com.apple.SoftwareUpdate.plist",
   	srcpath		    => "/Library/Preferences/"
);

sub getConfig       { return %config; }
sub getDescription  { return "Get OS last software update times"; }
sub getReferences   { return ""; }
sub getSourcePath   { return $config{srcpath}; }
sub getSourceFile   { return $config{srcfile}; }
sub getSourceType   { return $config{srctype}; }
sub getVersion      { return $config{version}; }
sub getApplyTo      { return $config{applyto}; }

#------------------------------------------------------------------------------
# helpers

my $VERSION = getVersion();
my $tab;
my $tab0 = '';
my $tab1 = '  ';
my $noalign = "%s";
my $align23 = "%-23s";
my $align25 = "%-25s";

#------------------------------------------------------------------------------

sub pluginmain {
	my $class = shift;
	my $plist = shift;
	::logMsg("Launching osxSwUpdate v.".$VERSION);
    die "Invalid PLIST object" if ( not defined $plist );

    my $name;
    my $data;
    my $timestamp;
    my $align = $align25;
    
    $name = 'LastAttemptDate';
    $data = ::getPlistKeyValue( $plist, $name );
    if ( not defined $data ) { $timestamp = 'Not found'; $data = ''; }
    else { $timestamp = ::macTimeToUTC( $data ); }
    ::rptMsg(sprintf($tab."$align = %s [%s]", $name, $timestamp, $data));

    $name = 'LastResultCode';
    $data = ::getPlistKeyValue( $plist, $name );
    $data = 'Not found' if not defined $data;
    ::rptMsg(sprintf($tab."$align = %s", $name, $data));
    
    $name = 'LastSuccessfulDate';
    $data = ::getPlistKeyValue( $plist, $name );
    if ( not defined $data ) { $timestamp = 'Not found'; $data = ''; }
    else { $timestamp = ::macTimeToUTC( $data ); }
    ::rptMsg(sprintf($tab."$align = %s [%s]", $name, $timestamp, $data));

    ::rptMsg("");
}

#------------------------------------------------------------------------------
1;